package com.wgl.express.util;

import com.wgl.express.entity.Package;

import java.util.InputMismatchException;
import java.util.Scanner;

import static com.wgl.express.text.Text.LINE;

public class Util {
    private Scanner input;
    private static Util instance;

    public Util() {
        this.input = new Scanner(System.in);
    }

    public  void say(String something){
        System.out.print(something);
    }

    public  String readLine(){
        return input.nextLine();
    }
    public int readInt(){
        int s = -1;
        try {
            s = input.nextInt();
        }catch (InputMismatchException e){
            say("请输入正确的数字！\n");
            input.nextLine();
        }
        return s;
    }
    public  float readFloat(){
        float s = -1f;
        try {
            s = input.nextFloat();
        }catch (InputMismatchException e){
            say("请输入正确的数字！\n");
            input.nextLine();
        }
        return s;
    }

    public static Util getUtil(){
        if (instance == null){
            instance = new Util();
        }
        return instance;
    }

    public  void showPackInfo(Package pack,boolean mask ){
        if (pack.getPid() != 0)  say("运单号：\t\t"+pack.getPid()+"\n");

        say("寄件人姓名：\t"+pack.getFromname()+"\n");

        if (mask) say("寄件人号码：\t"+pack.getFromphone()+"\n");
        else say("寄件人号码：\t"+pack.getMaskFromPhone()+"\n");

        say("寄件人地址：\t"+pack.getFromaddress()+"\n");
        say("收件人姓名：\t"+pack.getToname()+"\n");

        if (mask) say("收件人号码：\t"+pack.getTophone()+"\n");
        else say("收件人号码：\t"+pack.getMaskToPhone()+"\n");

        say("收件人地址：\t"+pack.getToaddress()+"\n");
        if (pack.getPrice()!=null) say("运费：\t\t"+pack.getPrice()+"\n");
        if (pack.getPickcode()!=null) say("取件码：\t\t"+pack.getPickcode()+"\n");
        switch (pack.getStatus()){
            case 1:say("状态：\t\t待揽收\n");break;
            case 2:say("状态：\t\t已入库\n");break;
            case 3:say("状态：\t\t已上架\n");break;
            case 4:say("状态：\t\t已出库\n");break;
            default:break;
        }
        say(LINE);
    }
    public  void showPackInfoUnPub(Package pack){
        say("运单号：\t\t"+pack.getPid()+"\n");
        say("寄件人姓名：\t"+"*"+pack.getFromname().substring(1)+"\n");
        say("寄件人号码：\t"+pack.getMaskFromPhone()+"\n");
        say("寄件人地址：\t"+pack.getMaskFromAddress()+"\n");
        say("收件人姓名：\t"+"*"+pack.getToname().substring(1)+"\n");
        say("收件人号码：\t"+pack.getMaskToPhone()+"\n");
        say("收件人地址：\t"+pack.getMaskToAddress()+"\n");

        if (pack.getPrice()!=null) say("运费：\t\t"+pack.getPrice()+"\n");
        switch (pack.getStatus()){
            case 1:say("状态：\t\t待揽收\n");break;
            case 2:say("状态：\t\t已入库\n");break;
            case 3:say("状态：\t\t已上架\n");break;
            case 4:say("状态：\t\t已出库\n");break;
            default:break;
        }
        say(LINE);
    }
}
